<?php


if (! file_exists(realpath(dirname(__FILE__)) . '/../vendor/autoload.php'))
    exit("autoload文件不存在");

require realpath(dirname(__FILE__)) . '/../vendor/autoload.php';

use paySdk\Pay;
use paySdk\functions\postar\lib\Request\Body\Order\AlipayOrder;

$now = time();
$order_expire = 15 * 60;

// 支付宝支付参数
$params = [
    "agent_id" => "61000000102111", "customer_id" => "60000000921011",
    "order_no" => date("YmdHis", $now),
    "device_no" => 123456, "tx_amt" => 100, "tx_amt_order" => 100,
    "client_ip" => "127.0.0.1",
    "alipay_buyer_account" => "alipay_buyer_account",
    "alipay_app_id" => "2088132324400955",
    "open_id" => "2088132324400955"
];

try {
    // 初始化时传入相关参数
    $order = new AlipayOrder($params);
    // 初始化时不穿入，通过__set方法设置参数
    /*$order = new AlipayOrder();
    foreach ($params as $key => $item) {
        $wechat_order->__set($key, $item);
    }*/

    // 实例化Pay，并把相关对象赋值给初始化参数数组的order键。生产环境下需要将mode设置为production
    $pay = new Pay(['order' => $order, "mode" => "testing"]);

    /* -- 日志与平台公钥可根据自己的需求重新设置路径，如果不设置，默认将日志放在/paySdk/log里，将平台公钥放在/paySdk/pem/postar下 -- */
    /*// 设置日志路径
    $pay->postar->setLog("/path/to/paysdk_log.log");
    // 设置平台公钥证书路径
    $pay->postar->setPlatformPublicKeyPath("/path/to/postar_platform_public_key.pem");*/

    // 调用pay方法
    $response = $pay->postar->pay();
    var_dump($response);

} catch (\Throwable $e) {
    echo "error msg: {$e->getMessage()}, file: {$e->getFile()}, line: {$e->getLine()} <br />";
    echo "error tracer: {$e->getTraceAsString()} <br />";
}